<?php
class Mnews_type extends CI_Model {
	
	public $table = 'tbl_news_type';
	public $pri_key="type_id";
	function __construct()

	{

		parent::__construct();

	}
	public function del_item($id)
	{
		$this->db->where($this->pri_key, $id);
		$this->db->delete($this->table); 
			
	}
	public function insert($data){

		if($this->db->insert($this->table,$data))
			return true;
		
		return false;

	}
	
		function update($data,$id,$lang)
	{
		if(is_numeric($id) && $id !='')
		{
			$this->db->where($this->pri_key,$id);
			$this->db->where("type_lang",$lang);
			
			if($this->db->update($this->table,$data))
				return true;
			return false;
			
		}
		return false;
	}
	
	public function get_last_id()
	{
			$this->db->order_by($this->pri_key,"DESC");
			return $this->db->get($this->table)->row_array();
	}
	
	public function info_form_id($id)
	{
		if(is_numeric($id) && $id !="")
		{
		$this->db->where($this->pri_key.' =',$id);
		$this->db->order_by('type_lang');
		return $this->db->get($this->table)->result_array();
		}
		else
			return false;
	}
	
	public function info_from_cat_id($id,$table)
	{
	
		if($table == 'tbl_product_cat')
		{
			$pri_key=$this->pri_key;
		}
	
		if(is_numeric($id) && $id !="")
		{
			$where = array($this->table.".".$this->pri_key => $id);
			$this->db->where($where);
			
		//	$this->db->join("tbl_product_cat" , "cat_id = prod_cate" );

	//		print_r($this->db->where());
			$query =$this->db->get($table); 
			return $query->result_array();
		}
		else
			return false;
	}
	public function check_name($name,$id="")
	{
		$this->db->where($this->name.' =',$name);
		if($this->db->count_all($this->table) >0)
			return true; // email nay da ton tai va ko su dung duoc
		return false; // co the su dung email nay
	}
	
	
	public function check_email($email)
	{
		$this->db->where('user_email =',$email);
		if($this->db->count_all($this->table) >0)
			return true; // email nay da ton tai va ko su dung duoc
		return false; // co the su dung email nay
			
 	}
	public function list_data($num,$off,$cid)
	{
		
		$this->db->where("cat_id",$cid);
		$this->db->limit($off,$num);
		$this->db->order_by($this->pri_key,"DESC");
		if($this->db->count_all($this->table) >0)
			//return $this->db->get($this->table)->result_array();
			{
				return $this->db->get($this->table)->result_array();
			}
		return false;
	}
	// dem so record 
	function count_all()
	{
		return $this->db->count_all_results($this->table);
	}
	
	public function get_data($lang)
	{
	
		if($this->db->count_all($this->table) >0)
			//return $this->db->get($this->table)->result_array();
			{
		
		$this->db->where('type_lang =',$lang);
		$this->db->where('cat_status =',1);
		$this->db->order_by($this->pri_key," ");
	return $this->db->get($this->table)->result_array();
			}
		return false;
	}
	

	function delete()

	{

		if (isset($_POST['checkbox1']))

		{

			foreach($_POST['checkbox1'] as $id) {

				$row = $this->info_from_cat_id($id,$this->table);
				$row = $row[0];
				if (!empty($row['cat_img_index'])) unlink("./upload/cate/".$row['cat_img_index']);
				$this->db->where($this->pri_key, $id);
				$this->db->delete($this->table); 
			
			}			

		}

	}
	function get_catdata($lg)
	{
		$this->db->where("cat_status",1);
		$catproduct = $this->db->get(" tbl_product_cat")->result_array();
		$catproduct = $this->get_product($catproduct);
		return $catproduct;
	}
	function get_product($catproduct)
	{
		if($catproduct != "")
		{
			$count = 0 ;
			foreach($catproduct as $item)
			{
				$this->db->where("prod_status",1);
				$this->db->where("prod_cate",$item["cat_id"]);
				$proname = $this->db->get("tbl_product")->result_array();
				$catproduct[$count++]["proname"] = $proname;
			}
			return $catproduct;
		}
		return $catproduct;
	}
}// model class

/* End of file mhumans.php */

/* Location: ./system/application/models/mhumans.php */

?>